#自动取款机 登陆、退出、查询余额、存款、取款

from db.atm_model import Model


#存储登录账户的信息


if __name__ == '__main__':
    mod = Model("atm")

    cid = ''
    pwd = ''

    client = {}

    print("="*20,"银行账户管理系统","="*20)
    print("\t1.登录账户\t\t2.退出账户")
    print("\t3.存款    \t\t4.取款")
    print("\t5.余额查询")
    print("="*58)

    while True:
        index = input("请输入操作序号：")
    #登录账户
        if index =='1':
            print("="*24,"登陆账户","="*24)
            cid = input("账号：")
            pwd = input("密码：")
            
            client = mod.findPWDByCID(cid)

            if client["pwd"] == pwd :
                print("登录成功！")
            else:
                print("登录失败！")
                cid = ''
                pwd = ''
                client = {}
            print("="*58)
    #退出账户       
        elif index =='2':
            print("="*24,"退出账户","="*24)
            if cid == '':
                print("您尚未登录账户!")
            else:
                cid = ''
                pwd = ''
                client = {}
                print("退出成功！")
                break
            print("="*58)
    #存款
        elif index =='3':
            print("="*24,"存款操作","="*24)
            print(client)
            if cid == '':
                print("您尚未登录账户!")
            else:
                m = float(input("请输入存款金额："))
                client["money"] += m
                print(client)
                mod.save(client)
                print("存款成功！")
            print("="*58)  
    #取款    
        elif index =='4':
            print("="*24,"取款操作","="*24)
            print(client)
            if cid == '':
                print("您尚未登录账户!")
            else:
                m = float(input("请输入取款金额："))
                client["money"] -= m
                print(client)
                mod.save(client)
                print("取款成功！")
            print("="*58)
    #余额查询        
        elif index =='5':
            print("="*24,"余额查询","="*24)
            if cid == '':
                print("您尚未登录账户!")
            else:
                m = client["money"]
                print("您的账户余额为：",m)
            print("="*58) 
